using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MCWEBSITE.BUL;
using MCWEBSITE.ENTITY;
using System.IO;

public partial class Modules_DVPJSC_wucOtherProducts : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int categoryId = Convert.ToInt32(Request.QueryString["CategoryId"]);
        int itemID = Convert.ToInt32(Request.QueryString["ItemID"]);
        if (categoryId == 0)
        {
            if (itemID == 0)
            {
                panelOtherProduct.Visible = false;
            }
            else
            {
                panelOtherProduct.Visible = true;
                websiteProductInfo objProduct = websiteProductBUL.Load(itemID);
                int prodCategory = objProduct.CategoryID;
                BindOtherCategories(prodCategory);

            }
        }
        else
        {
            panelOtherProduct.Visible = true;
            BindOtherCategories(categoryId);
        }

    }
    protected void BindOtherCategories(int categoryID)
    {
        List<websiteProductCategoryInfo> objCategory = websiteProductCategoryBUL.GetOtherParents(categoryID);
        dlOtherProducts.DataSource = objCategory;
        dlOtherProducts.DataBind();
    }
    protected void dlOtherProducts_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        HiddenField hd = (HiddenField)(e.Item.FindControl("hdfParentCategory"));
        string parentCatID = hd.Value;
        List<websiteProductInfo> objProduct1 = websiteProductBUL.SelectNtoMByLanguageAndCat(1, 4, "1", "vi-VN", Convert.ToInt32(parentCatID));
        foreach (websiteProductInfo obj in objProduct1)
        {
            string fileName = "";
            DirectoryInfo ThumbDirectory = new DirectoryInfo(Server.MapPath(obj.Image));
            foreach (FileInfo file in ThumbDirectory.GetFiles())
            {
                if (file.Name != "vssver2.scc" && file.Name != "Thumbs.db")
                    fileName = file.Name.ToString();
            }
            obj.Image += fileName;
            if (obj.Description.Length >= 20)
                obj.Description = obj.Description.Substring(0, 20) + " ...";
        }
        DataList dl1 = (DataList)(e.Item.FindControl("dl1stProduct"));
        dl1.DataSource = objProduct1;
        dl1.DataBind();
      
    }
    public string ConvertString(string strThumb)
    {
        if (strThumb != "")
            return strThumb.Remove(0, 2);
        return strThumb;
    }
}
